window: Add a default.activate action
authorMatthias Clasen <mclasen@redhat.com>
Sat, 27 Apr 2019 03:12:54 +0000 (03:12 +0000)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 28 Apr 2019 23:20:13 +0000 (23:20 +0000)
Activating this action will replace other
activate_default apis. It is more flexible,
since intermediate widgets can intercept the
action and do their own handling.

gtk/gtkwindow.c

index fd009aa832bd501edb256b564c6ce643b8f0083b..d3f00f89a3afa16cca3aa3fdd839351398824afe 100644 (file)
@@ -1773,6 +1773,31 @@ gtk_window_capture_motion (GtkWidget *widget,
   gtk_widget_set_cursor (widget, NULL);
 }
 
+static void
+activate_default_cb (GSimpleAction *action,
+                     GVariant      *parameter,
+                     gpointer       data)
+{
+  gtk_window_activate_default (GTK_WINDOW (data));
+}
+
+static void
+add_actions (GtkWindow *window)
+{
+  GActionEntry entries[] = {
+    { "activate", activate_default_cb, NULL, NULL, NULL },
+  };
+
+  GActionGroup *actions;
+
+  actions = G_ACTION_GROUP (g_simple_action_group_new ());
+  g_action_map_add_action_entries (G_ACTION_MAP (actions),
+                                   entries, G_N_ELEMENTS (entries),
+                                   window);
+  gtk_widget_insert_action_group (GTK_WIDGET (window), "default", actions);
+  g_object_unref (actions);
+}
+
 static void
 gtk_window_init (GtkWindow *window)
 {
@@ -1866,6 +1891,8 @@ gtk_window_init (GtkWindow *window)
   g_signal_connect_swapped (priv->key_controller, "focus-out",
                             G_CALLBACK (gtk_window_focus_out), window);
   gtk_widget_add_controller (widget, priv->key_controller);
+
+  add_actions (window);
 }
 
 static GtkGesture *